package com.lvwenna.userserver.service.impl;


import com.lvwenna.userserver.DTO.LoginParamsDTO;
import com.lvwenna.userserver.VO.UserInfoVO;
import com.lvwenna.userserver.dao.LoginMapper;
import com.lvwenna.userserver.entity.UserInfo;
import com.lvwenna.userserver.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public UserInfoVO login(LoginParamsDTO dto) {
        System.out.printf("登录1");
        String username = dto.getUsername();
        String password = dto.getPassword();
        System.out.println("用户名："+username);
        System.out.println("密码："+password);
        //从数据库查看有无对应的username  password

        UserInfo userInfo = loginMapper.selectUserInfo(username,password);
        if (userInfo==null||userInfo.getId()==null){
            System.out.println("登录失败");
            throw new RuntimeException("登录失败");
        }




        UserInfoVO userInfoVO = new UserInfoVO();
        userInfoVO.setNickName(userInfo.getNickname());
        userInfoVO.setAge(userInfo.getAge());
        return userInfoVO;
    }
}
